package io.renren.modules.app.controller.user.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.app.entity.YcUserExperienceEntity;
import io.renren.modules.app.entity.YcUserResumeEntity;
import io.renren.modules.app.service.YcUserExperienceService;
import io.renren.modules.app.service.YcUserResumeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;



/**
 * 
 *
 * @author lym
 * @email 928185446qq.com
 * @date 2023-12-21 17:02:58
 */
@RestController
@RequestMapping("userExperience")
public class YcUserExperienceController {
    @Autowired
    private YcUserExperienceService ycUserExperienceService;
    @Autowired
    private YcUserResumeService ycUserResumeService;


    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        String id= (String) params.get("userId");
        YcUserExperienceEntity UserExperience = ycUserExperienceService.getExperienceById(Integer.parseInt(id));
        return R.ok().put("UserExperience", UserExperience);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		YcUserExperienceEntity UserExperience = ycUserExperienceService.getById(id);
        return R.ok().put("UserExperience", UserExperience);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody Map<String, Object> requestData){
        ObjectMapper objectMapper = new ObjectMapper();
        YcUserExperienceEntity userExperience = objectMapper.convertValue(requestData.get("userExperience"), YcUserExperienceEntity.class);
        //获取userId
       String userId = (String) requestData.get("userId");
       //根据userId查询用户简历信息
       YcUserResumeEntity userResume = ycUserResumeService.getOne(new QueryWrapper<YcUserResumeEntity>().eq("user_id", userId));
       //获取简历id
       int userResumeId = userResume.getId();
       userExperience.setResumeId(userResumeId);
       userExperience.setAddtime(new Date());
       userExperience.setDeletestatus(false);
        System.out.println("123456"+userExperience);
       //保存实体
        ycUserExperienceService.save(userExperience);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody Map<String, Object> requestData){
        ObjectMapper objectMapper = new ObjectMapper();
        YcUserExperienceEntity userExperience = objectMapper.convertValue(requestData.get("userExperience"), YcUserExperienceEntity.class);
        ycUserExperienceService.updateById(userExperience);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("record:ycuserexperience:delete")
    public R delete(@RequestBody Integer[] ids){
		ycUserExperienceService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
